using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Rocuna.Core;

namespace Rocuna.GameEngine.State
{
    /// <summary>
    /// Manager for choosing active screen.
    /// </summary>
    public class ScreenManager
    {
        #region Constructor

        /// <summary>
        /// Initializes a new instance of the <see cref="ScreenManager"/> class.
        /// </summary>
        public ScreenManager()
        {
            Screens = new Dictionary<string, Screen>();
        }

        #endregion

        #region Properties

        /// <summary>
        /// Gets or sets the screens.
        /// </summary>
        /// <value>
        /// The screens.
        /// </value>
        private Dictionary<string, Screen> Screens { get; set; }

        /// <summary>
        /// Gets or sets the current screen.
        /// </summary>
        /// <value>
        /// The current screen.
        /// </value>
        public Screen CurrentScreen { get; set; }

        /// <summary>
        /// Registers the screen.
        /// </summary>
        /// <param name="screenName">Name of the screen.</param>
        /// <param name="screen">The screen.</param>
        public void RegisterScreen(string screenName, Screen screen)
        {
            Screens.Add(screenName, screen);
        }

        /// <summary>
        /// Gets the screen.
        /// </summary>
        /// <typeparam name="TScreen">The type of the screen.</typeparam>
        /// <returns></returns>
        public TScreen GetScreen<TScreen>() where TScreen : Screen
        {
            foreach (var screen in Screens)
            {
                if (screen.Value is TScreen)
                    return (TScreen)screen.Value;
            }
            return null;
        }

        /// <summary>
        /// Activates the screen.
        /// </summary>
        /// <param name="screenName">Name of the screen.</param>
        public void ActivateScreen(string screenName)
        {
            if (CurrentScreen != null)
                CurrentScreen.Deactivate();
            CurrentScreen = Screens[screenName];
            CurrentScreen.Activate();
        }

        /// <summary>
        /// Draws the specified game time.
        /// </summary>
        /// <param name="gameTime">The game time.</param>
        public void Draw(GameTime gameTime)
        {
            //CurrentScreen.Draw(gameTime);
        }

        #endregion
    }
}